package com.net.xpay.stat.scheduler;


import com.net.xpay.stat.task.PartnerUserDayStatDailyTask;
import com.net.xpay.common.helper.NoticeHelper;
import com.net.xpay.stat.task.PartnerDailyStatDailyTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 2019/7/15 16:28

 * 结算合伙人佣金
 */
@Slf4j
@Component
public class PartnerUserDayStatScheduler {

    @Autowired
    private PartnerUserDayStatDailyTask partnerUserDayStatDailyTask;

    @Autowired
    private PartnerDailyStatDailyTask partnerDailyStatDailyTask;

    @Autowired
    private NoticeHelper noticeHelper;

    /**
     * 每日2点 更新合伙人用户统计数据
     */

    @Scheduled(cron = "0 0 2 * * ?")
    public void doPartnerUserDayStat() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start schedule doPartnerUserDayStat|now={}", LocalDateTime.now());
            partnerUserDayStatDailyTask.startDailyWork();
            long t2 = System.currentTimeMillis();
            log.info("end schedule doPartnerUserDayStat|now={}|cost={}", LocalDateTime.now(), t2 - t1);
            noticeHelper.sendSystemInfoNotice("合伙人用户日统计数据生成完成，耗费时间：" + (t2 - t1), "text");
        } catch (Throwable e) {
            log.warn("doPartnerUserDayStat error", e);
            noticeHelper.sendSystemMonitorNotice("合伙人用户日统计数据失败|doPartnerUserDayStat error", "text");
        }
    }


    /**
     * 每日2点 更新合伙人统计数据
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void doPartnerDailyStatDailyTask() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start schedule partnerDailyStatDailyTask|now={}", LocalDateTime.now());
            partnerDailyStatDailyTask.startDailyWork();
            long t2 = System.currentTimeMillis();
            log.info("end schedule partnerDailyStatDailyTask|now={}|cost={}", LocalDateTime.now(), t2 - t1);
            noticeHelper.sendSystemInfoNotice("合伙人日统计数据生成完成，耗费时间：" + (t2 - t1), "text");
        } catch (Throwable e) {
            log.warn("partnerDailyStatDailyTask error", e);
            noticeHelper.sendSystemMonitorNotice("合伙人日统计数据失败|partnerDailyStatDailyTask error", "text");
        }
    }






}
